<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head> 
<body>
   
    <h1>编辑文章</h1>

    <form action="/update" method="POST">
       <!-- //设置隐藏域，把主键的值带给后台，作为更新的条件 -->
        <input type="hidden" id="id" name="id" value="">
        <p>
            标题： <input type="text" id="title" name="title" autocomplete="off">
        </p>
        <p>
            作者： <input type="text" id="author" name="author" autocomplete="off">
        </p>
        <p>
            审核： 
            <input type="radio" name="AudIt_status" value='0' > 待审核
            <input type="radio" name="AudIt_status" value='1' > 审核通过
            <input type="radio" name="AudIt_status" value='2' > 审核失败
        </p>
        <p>
            所属分类： 
            <select name="sort" id="sort">
                <option value="0">请选择</option>
                {{each sort item index}}
                    <option value="{{item.id}}">{{item.name}}</option>
                {{/each}}
            </select>
        </p>
        <p>
            内容：
            <textarea name="content" id="content"  cols="30" rows="10"></textarea>
        </p>
        <p>
            <button>确定更新</button>
        </p> 
    </form>
</body>
<script>
    window.onload=function(){
        let titleEle = document.getElementById('title');
        let authorEle = document.getElementById('author');
        let statusEle = document.getElementsByName("AudIt_status");
        let selectEle = document.getElementById("sort")
        let contentEle = document.getElementById("content");
        let options = document.querySelectorAll("#cat_id option");

        let status = "{{articles.Audit_status}}";
        let sort = "{{articles.sort}}";


        let input = [...statusEle].find((item) => item.value == status)
        input.checked = true;

        titleEle.value ="{{articles.title}}"
        authorEle.value = "{{articles.author}}"
        contentEle.value = "{{articles.content}}"
        selectEle.value = sort;

        let idEle = document.getElementById('id');
        let id="{{ articles.id}}";
        idEle.value = id;
    }

</script>
</html>